package io.renren.modules.neo4j.service.impl;

import io.renren.modules.neo4j.entity.node.course;
import io.renren.modules.neo4j.entity.node.knowledge;
import io.renren.modules.neo4j.respository.*;
import io.renren.modules.neo4j.service.CourseNeoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class CourseNeoServiceImpl implements CourseNeoService {

    @Autowired
    CourseRespository courseRespository;

    @Autowired
    OccupationRespository occupationRespository;

    @Autowired
    RelationShipRespository relationShipRespository;
    @Autowired
    BaseRelationshipRepository baseRelationship;
    @Autowired
    KnowledgeRespository knowledgeRespository;


    @Override
    public course addCourse(course course) {
        return courseRespository.save(course);
    }

    @Override
    public course getCourseByName(String name) {
        return courseRespository.getCourseByName(name);
    }

    @Override
    public boolean deleteCourseById(Long id) {
        return courseRespository.deleteCourseById(id);
    }

    @Override
    public Object findAll() {
        return courseRespository.findAll();
    }

    @Override
    public  List<Object> findShip(String name) {
        return baseRelationship.findPersonRelationshipByName( name);
    }

    @Override
    public course getKnowledgeByCourseId(Long id) {
        Optional<course> course = courseRespository.findById(id,1);
        course c = new course();
        if(null != course.get().getKnowledge()){
            c.setKnowledge(course.get().getKnowledge());
        }
        return c;
    }
}
